#include<iostream>
using namespace std;
const double * f1(const double ar[],int n);
const double * f2(const double [],int n);
const double * f3(const double *,int n);
int main()
{
	double av[3] = {1112.3,1542.6,227.9};
	// 声明函数指针同时初始化指针为f1
	const double *(*p1)(const double *,int) = f1;
	// 使用c++的auto关键字定义函数指针
	auto p2 = f2;
	cout<<"Using pointers to functions:\n";
	cout<<"Address Value\n";
	// 得到函数输出的地址和地址下的值
	cout<<(*p1)(av,3)<<":"<<*(*p1)(av,3)<<endl;
	cout<<p2(av,3)<<":"<<*p2(av,3)<<endl;
	// 声明函数指针数组
	const double *(*pa[3])(const double *,int) = {f1,f2,f3};
	// 声明自动变量
	auto pb = pa;
	cout<<"\nUsing an array of pointers to functions:\n";
	cout<<"Address Value\n";
	for(int i=0;i<3;i++)
	{
		cout<<pb[i](av,3)<<":"<<*pb[1](av,3)<<endl;
	}
	cout<<"\nUsing pointers to an array of function pointers:\n";
	cout<<"Address Value\n";
	// 获取指针数组的地址
	auto pc=&pa;
	//(*pc)[0]表示指针数组第一个函数指针
	cout<<(*pc)[0](av,3)<<":"<<*(*pc)[0](av,3)<<endl;
	// 定义(*pd)[3]pd是指向三个函数指针的数组，*pd就是数组
	const double *(*(*pd)[3])(const double *,int) = &pa;
	const double * pdb = (*pd)[1](av,3);
	cout<<"(*(*pd)[2])(av,3)"<<":"<<*(*(*pd))(av,3)<<endl;
	return 0;
}
const double *f1(const double *ar,int n)
{
	return ar;
}
const double *f2(const double ar[],int n)
{
	return ar+1;
}
const double *f3(const double ar[],int n)
{
	return ar+2;
}
